/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */
import type { MaFormItem } from "@mineadmin/form";
import hasAuth from "@/utils/permission/hasAuth.ts";
import MaUploadFile from "@/components/ma-upload-file/index.vue";
import { concat } from "lodash-es";
import MaRemoteSelect from "@/components/ma-remote-select/index.vue";
import MaDictSelect from "@/components/ma-dict-picker/ma-dict-select.vue";
import { page as merchantPage } from "$/attractions/commerce/api/commerceMerchant.ts";

export default function getFormItems(
  formType: "add" | "edit" = "add",
  t: any,
  model: any
): MaFormItem[] {
  return concat([
    {
      label: "商户名称",
      prop: "merchant_id",
      render: () => MaRemoteSelect,
      renderProps: {
        api: merchantPage,
        dataHandle: (response: any) => {
          if (response.code === 200 && response.data && response.data.list) {
            return response.data.list.map((item: any) => ({
              label: item.merchant_name || `商户名称${item.id}`,
              value: item.id,
            }));
          }
          return [];
        },
        placeholder: "请选择商户名称",
        clearable: true,
        multiple: false,
      },
      itemProps: { rules: [{ required: true, message: "请选择商户名称" }] },
    },
    {
      label: "合同标题",
      prop: "contract_title",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "合同标题" }) },
      itemProps: { rules: [{ required: true, message: "请输入合同标题" }] },
    },
    {
      label: "甲方",
      prop: "party_a",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "甲方" }) },
      itemProps: { rules: [{ required: true, message: "请输入甲方" }] },
    },
    {
      label: "乙方",
      prop: "party_b",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "乙方" }) },
      itemProps: { rules: [{ required: true, message: "请输入乙方" }] },
    },
    {
      label: "合同金额（元）",
      prop: "contract_amount",
      render: "input",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "合同金额" }),
        type: "number",
      },
    },
    {
      label: "付款方式",
      prop: "payment_method",
      render: () => MaDictSelect,
      renderProps: {
        data: [
          { label: "银行转账", value: 1 },
          { label: "微信支付", value: 2 },
          { label: "支付宝支付", value: 3 },
          { label: "现金", value: 4 },
          { label: "其他付款方式", value: 5 },
        ],
        placeholder: t("form.pleaseInput", { msg: "付款方式" }),
        clearable: true,
        multiple: false,
      },
    },
    {
      label: "签订时间",
      prop: "sign_date",
      render: "DatePicker",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "签订时间" }),
        type: "date",
        format: "YYYY-MM-DD",
        valueFormat: "YYYY-MM-DD",
      },
      itemProps: { rules: [{ required: true, message: "请输入签订时间" }] },
      mode: "date",
      showTime: false,
    },
    {
      label: "生效日期",
      prop: "effective_date",
      render: "DatePicker",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "生效日期" }),
        type: "date",
        format: "YYYY-MM-DD",
        valueFormat: "YYYY-MM-DD",
      },
      itemProps: { rules: [{ required: true, message: "请输入生效日期" }] },
      mode: "date",
      showTime: false,
    },
    {
      label: "到期日期",
      prop: "expiry_date",
      render: "DatePicker",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "到期日期" }),
        type: "date",
        format: "YYYY-MM-DD",
        valueFormat: "YYYY-MM-DD",
      },
      itemProps: { rules: [{ required: true, message: "请输入到期日期" }] },
      mode: "date",
      showTime: false,
    },
    {
      label: "合同文件路径",
      prop: "contract_file",
      render: () => MaUploadFile,
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "合同文件路径" }),
      },
      multiple: false,
    },
    {
      label: "附件文件路径",
      prop: "attachment_files",
      render: () => MaUploadFile,
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "附件文件路径" }),
      },
      multiple: true,
    },
  ]);
}
